package com.foxmail.aroundme.boring.weight;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.foxmail.aroundme.boring.R;


/**
 * Created by lianzhan on 16/9/28.
 */
public class MenuLineaLayout extends LinearLayout {

    public MenuLineaLayout(Context context) {
        super(context);
        initView(context, null);
    }

    public MenuLineaLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);
    }

    public MenuLineaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context, attrs);
    }

    private void initView(Context context, AttributeSet attributeSet) {
        LayoutInflater.from(context).inflate(R.layout.view_menu, this, true);

        if (attributeSet == null) {
            return;
        }

        ImageView imageView = (ImageView) findViewById(R.id.menu_image);
        TextView textView = (TextView) findViewById(R.id.menu_info);

        TypedArray array = context.obtainStyledAttributes(attributeSet, R.styleable.attr_menu);
        int imageId = array.getResourceId(R.styleable.attr_menu_image, -1);
        int infoId = array.getResourceId(R.styleable.attr_menu_info, -1);

        if (imageId > -1) {
            imageView.setVisibility(VISIBLE);
            imageView.setImageResource(imageId);
        }

        if (infoId > -1) {
            textView.setText(infoId);
        }

        array.recycle();
    }

}
